package cn.itcast.test.createThreadMethod;

import lombok.extern.slf4j.Slf4j;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

@Slf4j(topic = "c.test3")
public class test3 {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
//原始
//        FutureTask<Integer> futureTask = new FutureTask<>(new Callable<Integer>() {
//            @Override
//            public Integer call() throws Exception {
//                log.debug("running");
//                Thread.sleep(1000);
//                return 100;
//            }
//        });

//lambda表达式简化
        FutureTask<Integer> futureTask = new FutureTask<>(() -> {
            Thread.sleep(1000);
            log.debug("running");
            return 100;
        });

        Thread t = new Thread(futureTask,"自定义名称");
        log.debug("start");
        t.start();
        System.out.println(futureTask.get());
    }


}
